package com.neu.config;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotRoleException;
import com.neu.constant.ResultCodeEnum;
import com.neu.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NotLoginException.class)
    public Result NotLoginException(NotLoginException e) {
        log.info("未登录异常", e);
        return Result.error(ResultCodeEnum.NOT_LOGIN);
    }
    @ExceptionHandler(NotRoleException.class)
    public Result NotRoleException(NotRoleException e) {
        log.info("角色无权限异常", e);
        return Result.error(ResultCodeEnum.NOT_ROLE);
    }
    @ExceptionHandler(NoHandlerFoundException.class)
    public Result handleNoHandlerFoundException(NoHandlerFoundException e) {
        return Result.error(ResultCodeEnum.NOT_FOUND);
    }
    @ExceptionHandler(Exception.class)
    public Result Execption(Exception e) {
        log.error("error!!!", e);
        return Result.error(ResultCodeEnum.FAIL);
    }
}
